/*
 * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum ingilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package cn.itenzo.common.validate;

import com.baidu.unbiz.fluentvalidator.Validator;
import com.baidu.unbiz.fluentvalidator.ValidatorContext;
import com.baidu.unbiz.fluentvalidator.ValidatorHandler;

import java.util.Date;

/**
 * 开始时间和结束时间校验
 * @author ENZO
 */
public class StartEndTmeValidate extends ValidatorHandler<Date> implements Validator<Date> {
	
	
	private Date startTime;
	private Date endTime;
	

	/**
	 * 
	 * @param starttime  开始时间
	 * @param endtime   结束时间
	 */
	public StartEndTmeValidate(Date starttime, Date endtime) {
		this.startTime = starttime;
		this.endTime = endtime;
	}



	@Override
	public boolean validate(ValidatorContext context, Date t) {
		if(null == startTime || null == endTime){
			context.addErrorMsg("未输入有效的时间");
			return false;
		}
		
		if(endTime.getTime() < startTime.getTime()){
			context.addErrorMsg("结束时间小于开始时间");
			return false;
		}
		return true;
	}

}
